package com.ityc.controller;


import com.ityc.anno.Log;
import com.ityc.pojo.Clazz;
import com.ityc.pojo.ClazzQueryParam;
import com.ityc.pojo.PageResult;
import com.ityc.pojo.Result;
import com.ityc.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    /*
    * 班级列表数据的条件分页查询
    * */
    @GetMapping
    public Result page(ClazzQueryParam clazzQueryParam) {
        log.info("分页查询,参数:{}",clazzQueryParam);
        PageResult<Clazz> pageResult = clazzService.page(clazzQueryParam);
        return Result.success(pageResult);
    }

    @Log
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除班级:{}", id);
        clazzService.deleteById(id);
        return Result.success();
    }
    @Log
    @PostMapping
    public Result save(@RequestBody Clazz clazz) {
        log.info("保存班级,参数:{}",clazz);
        clazzService.save(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        log.info("获取班级信息,id:{}",id);
        Clazz clazz = clazzService.getById(id);
        return Result.success(clazz);
    }

    @Log
    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        log.info("更新班级,参数:{}",clazz);
        clazzService.update(clazz);
        return Result.success();
    }

    @GetMapping("/list")
    public Result list() {
        log.info("查询所有班级信息");
        List<Clazz> clazzList = clazzService.list();
        return Result.success(clazzList);
    }
}
